<?php
/**
 * Created by PhpStorm.
 * User: 91336
 * Date: 13-12-12
 * Time: 下午3:50
 */

class member_base
{
    private static $db;

    public static function  get_db($model = 'member_model'){
        return pc_base::load_model($model);
    }

    /**
     * 检查密码是否正确
     * @param $password
     * @return bool
     */
    public static function _checkpasswd($password){
        if (!is_password($password)){
            return false;
        }
        return true;
    }

    /**
     * 检查用户名是否允许
     * @param $username
     * @return bool
     */
    public static function  _checkname($username) {
        $username =  trim($username);
        if (self::get_db()->get_one(array('username'=>$username))){
            return false;
        }
        return true;
    }

    /**
     * 转化数据串
     * @param $data
     * @return string
     */
    public static function auth_data($data) {
        $s = $sep = '';
        foreach($data as $k => $v) {
            if(is_array($v)) {
                $s2 = $sep2 = '';
                foreach($v as $k2 => $v2) {
                    $s2 .= "$sep2{$k}[$k2]=". ps_stripslashes($v2);
                    $sep2 = '&';
                }
                $s .= $sep.$s2;
            } else {
                $s .= "$sep$k=". ps_stripslashes($v);
            }
            $sep = '&';
        }

        $auth_s = urlencode(sys_auth($s));
        return $auth_s;
    }
}